package org.example.modbusdemo;

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.example.heartbeat.MyServerHandler;
import org.example.modbus.ModbusClientHandler;
import org.example.modbus.ModbusMessageEnCoder;

import java.util.Scanner;

public class ModBusClient {


    public static void main(String[] args) throws InterruptedException {


        EventLoopGroup eventExecutors = new NioEventLoopGroup();
        //创建客户端启动对象
        Bootstrap bootstrap =new Bootstrap();
        bootstrap.group(eventExecutors)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel channel) throws Exception {
                        channel.pipeline().addLast(new ModbusMessageEnCoder());
                        channel.pipeline().addLast(new ModbusClientHandler());//加入自己的处理器
                    }
                });
        System.out.println("客户端 ok..");
        ChannelFuture channelFuture = bootstrap.connect("127.0.0.1",502).sync();


        Channel channel = channelFuture.channel();
        Scanner scanner =new Scanner(System.in);

    }


}
